use crate::block;

pub struct BlockChain {
    pub blocks: Vec<block::Block>,
}

impl BlockChain {
    pub fn add_block(&mut self, data: String) {
        let pre_block = &self.blocks[self.blocks.len() - 1];
        let new_block = block::Block::new_block(data, pre_block.hash.clone());
        self.blocks.push(new_block);
    }
    fn new_genesis_block() -> block::Block {
        // block::Block{String::from("")}
        block::Block::new_block("genesis block".to_string(), String::from(""))
        // block::Block {
        //     header: BlockHeader {
        //         time: 0,
        //         tx_hash: "".to_string(),
        //         pre_hash: "".to_string(),
        //     },
        //     hash: String::from("genesis block"),
        //     data: "genesis block".to_string(),
        // }
    }
    pub fn new_blockchain() -> BlockChain {
        BlockChain {
            blocks: vec![BlockChain::new_genesis_block()]
        }
    }
}
